package SpaceIT.pages;

import java.text.DecimalFormat;
import model.pojo.Cart;
import model.pojo.ThongTinKhachHang;

import org.apache.tapestry5.Block;
import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.ioc.annotations.Inject;

import view.util.util;

public class ThanhToan 
{	
	@Property
	private int i;
	
	@Property
	private util viewHelper ;

	@ApplicationState
	private model.pojo.Cart arrGioHang;
	
	@ApplicationState
	private ThongTinKhachHang ttKH;

	@Property
	private String hoTen;
	
	@Property
	private String diaChiMail;
	
	@Property
	private String diaChi;
	
	@Property
	private String dienThoaiBan;
	
	@Property
	private String diDong;
		
	public ThanhToan(){
//	{
		viewHelper = new util();
	}
	
	public int getSizeCart(){
//	{
		if(arrGioHang != null)
			return arrGioHang.Size();
		return 0;
	}
	
	public String getMaSP(int i){
//	{
		return arrGioHang.get(i).getMaSP();
	}
	
	public String getTenSP(int i){
//	{
		return arrGioHang.get(i).getTenSP();
	}
	
	public String getGiaBan(int i){
//	{
		DecimalFormat myFormatter = new DecimalFormat("###,###");
		String s = myFormatter.format(arrGioHang.get(i).getGiaBan()); 
		return s;
	}
	
	public String getLinkHinh(int i){
//	{
		return arrGioHang.get(i).getLinkHinh();
	}
	
	public String getLinkChiTiet(int i){
//	{
		return (arrGioHang.get(i).getLinkChiTiet() + arrGioHang.get(i).getMaSP());
	}
	
	public String getSoLuong(int i){
//	{
		return Integer.toString(arrGioHang.get(i).getSoLuong());
	}
	
	public String getTongTien(){
//	{
		int s = arrGioHang.TongTien();
		DecimalFormat myFormatter = new DecimalFormat("###,###");
		return myFormatter.format(s);
	}
	
	@OnEvent(value="submit", component="formThanhToan")
	Object onFormSubmit() 
	{		
		ttKH.setDiaChiKH(diaChi);
		ttKH.setDTBan(dienThoaiBan);
		ttKH.setDTDD(diDong);
		ttKH.setMailKH(diaChiMail);
		ttKH.setTenKH(hoTen);
		return expresscheckout.class;
	}
}
